<template>
  <div>
    <button @click="changeState">切换</button>
    <p v-if="state" style="float: left" ref="myP">今天又下雨了</p>
  </div>
</template>

<script>
export default {
  name: "NextTickDemo",
  data() {
    return {
      state: false,
    };
  },
  updated() {
    // console.log(this.$refs.myP);
  },
  methods: {
    changeState() {
      this.state = !this.state; // 异步更新

      this.$nextTick(function () {
        console.log(this.$refs.myP.offsetWidth);
      });
    },
  },
};
</script>